from django.db import models
from django.utils import timezone


class Capital(models.Model):
    henan = models.CharField(max_length=3, default='河南')
    cs = models.CharField(max_length=3, null=True)
    blac = models.CharField(blank=True, max_length=200)
    nu_1 = models.IntegerField()
    times = models.DateField(default=timezone.now)


class Human(models.Model):
    name = models.CharField(max_length=20)
    sex = models.CharField(max_length=1, default='男')
    age = models.CharField(max_length=3, default='18')
    identity = models.CharField(max_length=18)
    height = models.ManyToManyField(Capital)
    times = models.DateField(default=timezone.now)


class Tests(models.Model):
    SUBJECT = (
        ('E', 'English'),
        ('M', 'Math'),
        ('L', 'Language')
    )
    language = models.CharField(max_length=3, default='')
    math = models.CharField(max_length=3, default='')
    english = models.CharField(max_length=3, default='')
    human_name = models.ForeignKey(Human, on_delete=models.CASCADE)
    merit = models.CharField(max_length=1, choices=SUBJECT, default='')
    times = models.DateField(default=timezone.now)


class Student(models.Model):
    ids = models.CharField(max_length=10)
    cj = models.OneToOneField(Human, on_delete=models.CASCADE)
    times = models.DateField(default=timezone.now)


class Mo(models.Model):
    user_id = models.IntegerField()

    class Meta:
        # 设置本model为抽象类，仅能被其他model继承，本model不会生成数据库表
        abstract = True


class Log(Mo):
    mess = models.CharField(max_length=200)


class Us(Mo):
    mes_id = models.IntegerField()

    class Meta:

        abstract = True


class Us_2(Us):
    pass


class Use1(models.Model):
    user_id = models.IntegerField()

    class Meta:
        db_table = "my name is Use1" # 修改表明


class Use2(models.Model):
    head = models.CharField(max_length=200)

    class Meta:

        db_tablespace = "fish"
        # 修改表的命名空间


class Foo(models.Model):
    pass


class Bar(models.Model):
    foo = models.ForeignKey(Foo,on_delete=models.CASCADE)
    pud_date = models.DateTimeField(default=timezone.now)

    class Meta:
        default_related_name = 'bars'
        ordering = ['-id'] # 设置排序规则 先按id，后时间


